﻿namespace Vibstudio.NetConfigurator.UI.ViewModels
{
    #region Namespaces

    using System.Windows.Forms;
    using System.Windows.Input;

    using Vibstudio.NetConfigurator.Globalization;
    using Vibstudio.NetConfigurator.UI.Common;
    using Vibstudio.NetConfigurator.UI.Model;

    #endregion

    public class ResultValidationFileViewModel : ViewModelBase
    {
        #region Fields

        private RelayCommand _executeAutoCompositionCommand;

        private RelayCommand _goToHomeCommand;

        private ResultValidationFileCollection _result;

        private bool _autocompositionVisibility;

        #endregion

        #region Ctor(s)

        public ResultValidationFileViewModel(ResultValidationFileCollection result)
        {
            _autocompositionVisibility = IsAutocompositionVisible();
            Result = result;
        }

        #endregion

        #region Public Properties

        public bool AutocompositionVisibility
        {
            get { return _autocompositionVisibility; }
            set
            {
                _autocompositionVisibility = value;
                OnPropertyChanged("AutocompositionVisibility");
            }
        }

        public ICommand ExecuteAutoCompositionCommand
        {
            get
            {
                return _executeAutoCompositionCommand ??
                       (_executeAutoCompositionCommand =
                        new RelayCommand(param => ExecuteAutoComposition()));
            }
        }

        public ICommand GoToHomeCommand
        {
            get { return _goToHomeCommand ?? (_goToHomeCommand = new RelayCommand(GoToHome)); }
        }

        public ResultValidationFileCollection Result
        {
            get { return _result; }
            set
            {
                _result = value;
                base.OnPropertyChanged("Result");
            }
        }

        #endregion

        #region Methods

        private void ExecuteAutoComposition()
        {
            //TODO: Implements autocomposition!

            var dialog = new FolderBrowserDialog
                             {
                                 Description =
                                     Labeler.Get.ChooseApplicationsPathToAutoCompose.ToString()
                             };

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string rootPath = dialog.SelectedPath;

                ViewModelLocator.SetChild(ViewRepository.Get.Home());
            }

        }

        private void GoToHome(object o)
        {
            ViewModelLocator.SetChild(ViewRepository.Get.Home());
        }

        private bool IsAutocompositionVisible()
        {
            return false;
        }

        #endregion
    }
}